"""
url：http://8.140.193.160:8899/admin/home/
步骤：
1、输入账号
2、输入密码
3、输入验证码
4、点击登录
5、判断登录是否成功
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
class CRMEB:
    def __init__(self,driver):
        self.driver = driver
        self.driver.maximize_window()
    def open_url(self,url): # 打开浏览器
        self.driver.get(url)
        self.driver.implicitly_wait(15)
    def input_user(self,user):
        """
        :param user: 输入账号
        :return:
        """
        account = self.driver.find_elements(By.CLASS_NAME,"ivu-input")[0]
        account.clear()
        account.send_keys(user)
    def input_password(self,pwd):
        """
        :param pwd: 输入密码
        :return:
        """
        password = self.driver.find_elements(By.CLASS_NAME,"ivu-input")[1]
        password.clear()
        password.send_keys(pwd)
    def input_img(self,imgcode):
        img = self.driver.find_elements(By.CLASS_NAME,"ivu-input")[2]
        img.clear()
        img.send_keys(imgcode)
    def click_login(self):
        self.driver.find_element(By.CLASS_NAME,"btn").click()
    def assert_text(self):
        text = self.driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/div[2]/div/div[2]/div/div[1]/div[2]/div/div[1]/p/span").text
        assert "用户访问量" == text
    def quit_driver(self):
        self.driver.quit()

if __name__ == '__main__':
    driver = webdriver.Chrome()
    c1 = CRMEB(driver)
    c1.open_url("http://8.140.193.160:8899/admin/home/")
    c1.input_user("admin")
    c1.input_password("920509")
    c1.input_img('a')
    c1.click_login()
    c1.assert_text()
    c1.quit_driver()












